﻿Public Class frmOpciones

    Private Sub frmOpciones_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        mdiPrincipal.tsmiOptions.Enabled = True
    End Sub

    Private Sub frmOpciones_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        mdlHerramientas.loadOption()



        Me.txtExaminarShell.Text = mdlHerramientas.strRutaSirius
        Me.nudNumintentos.Value = mdlHerramientas.intNumintentos
        Me.txtURL.Text = mdlHerramientas.strUrl
        Me.txtUsuariows.Text = mdlIntegracion.athUsuario
        Me.txtPasswordws.Text = mdlIntegracion.athContrasenia
        Me.txtServidor.Text = mdlHerramientas.strServer
        Me.txtPuerto.Text = mdlHerramientas.strPort
        Me.txtBasedatos.Text = mdlHerramientas.strDatabase
        Me.txtUsuario.Text = mdlHerramientas.strUid
        Me.txtContrasenia.Text = mdlHerramientas.strPwd
        Me.chkTurnero.Checked = mdlHerramientas.boolTurnero
        Me.chkCabecera.Checked = mdlHerramientas.boolCabecera
        Me.txtBasedatosws.Text = mdlHerramientas.strDatabasews
        Me.txtFotografia.Text = mdlHerramientas.strRutafotografia
        Me.txtHuelladerecha.Text = mdlHerramientas.strRutahuelladerecha
        Me.txtHuellaizquierda.Text = mdlHerramientas.strRutahuellaizquierda
        Me.txtNombre.Text = mdlHerramientas.strCrcNombre
        Me.txtRazon.Text = mdlHerramientas.strCrcRazon
        Me.txtTelefono.Text = mdlHerramientas.strCrcTelefono
        Me.txtDireccion.Text = mdlHerramientas.strCrcDireccion
        Me.txtNit.Text = mdlHerramientas.strCrcNit
        Me.txtLogo.Text = mdlHerramientas.strCrcRutalogo
        Me.txtLogoAlt.Text = mdlHerramientas.strCrcRutalogoAlt
        Me.txtResolucion.Text = mdlHerramientas.strCrcResolucion
        Me.txtOnac.Text = mdlHerramientas.strCrcOnac
        Me.txtCodigoPre.Text = mdlHerramientas.strCrcCodigoPre
        Me.txtEncabezado.Text = mdlHerramientas.strCrcEncabezado
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAceptar.Click
        mdlHerramientas.saveOption(Me)
        mdlHerramientas.loadOption()
        Me.Close()
    End Sub

    Private Sub btnExaminarShell_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExaminarShell.Click
        Dim ofdShell As New OpenFileDialog()

        With ofdShell
            .Title = "Seleccionar programa Sirius"
            .Filter = "*.exe|*.exe"
            .Multiselect = False
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                Me.txtExaminarShell.Text = .FileName
            End If
        End With
    End Sub

    Private Sub btnProbarconexion_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProbarconexion.Click
        Me.prbConexion("postgres")
    End Sub

    Private Sub prbConexion(ByVal strDB As String)
        Dim Err As String = ""

        If Me.txtServidor.Text.Trim = "" Then
            Err = Err & Chr(13) & "* Debe identificar el servidor de la base de datos."
        End If

        If Me.txtPuerto.Text.Trim = "" Then
            Err = Err & Chr(13) & "* Debe identificar el Puerto de conexión."
        End If

        If Me.txtUsuario.Text.Trim = "" Then
            Err = Err & Chr(13) & "* Debe identificar el usuario de conexión."
        End If

        If strDB.ToString = "" Then
            Err = Err & Chr(13) & "* Debe especificar la base de datos."
        End If

        If Err <> "" Then
            MsgBox("Advertencia:" & Err.ToString, MsgBoxStyle.Exclamation, "Base de datos")
        Else
            mdlHerramientas.probarConexion(Me.txtServidor.Text, Me.txtPuerto.Text, strDB.ToString, Me.txtUsuario.Text, Me.txtContrasenia.Text)
        End If
    End Sub

    Private Sub btnValidarcrc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidarcrc.Click
        Me.prbConexion(Me.txtBasedatos.Text)
    End Sub

    Private Sub btnWsvalidar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWsvalidar.Click
        Me.prbConexion(Me.txtBasedatosws.Text)
    End Sub

    Private Sub btnFFotografia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFFotografia.Click
        If Me.fbdRutas.ShowDialog() = DialogResult.OK Then
            Me.txtFotografia.Text = Me.fbdRutas.SelectedPath
        End If
    End Sub

    Private Sub btnFHuelladerecha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFHuelladerecha.Click
        If Me.fbdRutas.ShowDialog() = DialogResult.OK Then
            Me.txtHuelladerecha.Text = Me.fbdRutas.SelectedPath
        End If
    End Sub

    Private Sub btnFHuellaizquierda_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFHuellaizquierda.Click
        If Me.fbdRutas.ShowDialog() = DialogResult.OK Then
            Me.txtHuellaizquierda.Text = Me.fbdRutas.SelectedPath
        End If
    End Sub

    Private Sub btnFLogo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFLogo.Click
        If Me.pfdRutas.ShowDialog() = DialogResult.OK Then
            Me.txtLogo.Text = Me.pfdRutas.FileName

        End If
    End Sub

    Private Sub btnFLogoAlt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFLogoAlt.Click
        If Me.pfdRutas.ShowDialog() = DialogResult.OK Then
            Me.txtLogoAlt.Text = Me.pfdRutas.FileName

        End If
    End Sub
End Class